from django.db import models
from ThreeLogin.models import BaseModel, UserProfile


# 商品model
class Goods(models.Model):
    name = models.CharField(max_length=120)
    price = models.DecimalField(max_digits=8, decimal_places=2)
    content = models.TextField('详情')
    pic = models.ImageField(upload_to="goods")
    stock = models.IntegerField('库存')
    sale = models.IntegerField('销量', default=0)

# 订单model
class Order(BaseModel):
    PAY_CHOICE = ((1, "支付宝"), (2, "微信"), (3, "货到付款"))
    sn = models.CharField(max_length=20)
    total = models.DecimalField(max_digits=8, decimal_places=2)
    pay = models.SmallIntegerField(choices=PAY_CHOICE)
    status = models.SmallIntegerField(default=1)  # 1 未支付  2  已支付
    user = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
    trade_no = models.CharField("支付宝交易号", max_length=30, null=True)

    class Meta:
        db_table = "orders"

# 订单详情model
class OrderItem(models.Model):
    goods = models.ForeignKey(Goods, on_delete=models.CASCADE)
    order = models.ForeignKey(Order, on_delete=models.CASCADE, related_name="items")
    num = models.IntegerField()

    class Meta:
        db_table = "order_item"
